www.gusucode.com > VC++ 自制SQL数据库,含有服务端+客户端-源码程序 > VC++ 自制SQL数据库,含有服务端+客户端-源码程序/code/Client/clientDoc.cpp

    // clientDoc.cpp : implementation of the CClientDoc class
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "client.h"
#include "Msg.h"

#include "clientDoc.h"
#include "clientView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CClientDoc

IMPLEMENT_DYNCREATE(CClientDoc, CDocument)

BEGIN_MESSAGE_MAP(CClientDoc, CDocument)
	//{{AFX_MSG_MAP(CClientDoc)
	ON_COMMAND(ID_OP_EXEC, OnOpExec)
	ON_UPDATE_COMMAND_UI(ID_OP_EXEC, OnUpdateOpExec)
	ON_COMMAND(ID_OP_STEP_EXEC, OnOpStepExec)
	ON_UPDATE_COMMAND_UI(ID_OP_STEP_EXEC, OnUpdateOpStepExec)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientDoc construction/destruction

CClientDoc::CClientDoc()
{
	memset(&m_lf, 0, sizeof(m_lf));
	m_lf.lfWeight = FW_NORMAL;
	m_lf.lfCharSet = DEFAULT_CHARSET;
	m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf.lfQuality = DEFAULT_QUALITY;
	m_lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	strcpy(m_lf.lfFaceName, "宋体");
}

CClientDoc::~CClientDoc()
{
}

BOOL CClientDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	((CCrystalEditView* )m_viewList.GetHead())->SetWindowText("");
	m_TextBuffer.InitNew();

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CClientDoc serialization

void CClientDoc::Serialize(CArchive& ar)
{
	CCrystalEditView* pView = (CCrystalEditView*)m_viewList.GetHead();
	ASSERT_VALID(pView);
	ASSERT_KINDOF(CCrystalEditView, pView);

	if (ar.IsStoring())	
	{
	} 
	else 
	{
	}

	ASSERT_VALID(this);
}

/////////////////////////////////////////////////////////////////////////////
// CClientDoc diagnostics

#ifdef _DEBUG
void CClientDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CClientDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CClientDoc commands

BOOL CClientDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	return m_TextBuffer.LoadFromFile(lpszPathName);
}

BOOL CClientDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	return m_TextBuffer.SaveToFile(lpszPathName);
}

void CClientDoc::DeleteContents() 
{
	CDocument::DeleteContents();
	m_TextBuffer.FreeAll();
}

void CClientDoc::OnOpExec() 
{
	theApp.m_ClientDocList.AddTail( this );

	CString str;
	if( m_TextBuffer.GetLineCount () > 0 )
		m_TextBuffer.GetText(0,0,m_TextBuffer.GetLineCount ()-1,
			m_TextBuffer.GetLineLength(m_TextBuffer.GetLineCount ()-1),str);
	else
		str = _T("");

	CMsg msg( COMMAND );
	msg.m_msgList.AddTail( str );
	theApp.SendMsg( msg );
}

void CClientDoc::OnUpdateOpExec(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( theApp.m_bConnection );
}

void CClientDoc::OnOpStepExec() 
{
	theApp.m_ClientDocList.AddTail( this );

	CString str;
	if( m_TextBuffer.GetLineCount () > 0 )
		m_TextBuffer.GetText(0,0,m_TextBuffer.GetLineCount ()-1,
			m_TextBuffer.GetLineLength(m_TextBuffer.GetLineCount ()-1),str);
	else
		str = _T("");

	CMsg msg( STEP_COMMAND );
	msg.m_msgList.AddTail( str );
	theApp.SendMsg( msg );
}

void CClientDoc::OnUpdateOpStepExec(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( theApp.m_bConnection );
}